package com.bytedance.common.databinding;

import java.util.ArrayList;
import java.util.List;

public class b<C, T, A> implements Cloneable {
    public static abstract class a<C, T, A> {
        public a() {

        }

        public abstract void a(C arg1, T arg2, int arg3);
    }

    private List<C> a;
    private long b;
    private long[] c;
    private int d;
    private final a<C, T, A> e;

    public b(a arg3) {

        this.a = new ArrayList();
        this.b = 0;
        this.e = arg3;
    }

    private b a() {
        int v1_2;
        CloneNotSupportedException v1_1;
        long v4;
        Object v0_1;
        b v1 = null;
        synchronized (this) {
            try {
                v0_1 = super.clone();
                v4 = 0;
                ((b) v0_1).b = v4;
                ((b) v0_1).c = null;
                ((b) v0_1).d = 0;
                ((b) v0_1).a = new ArrayList();
                int v3 = this.a.size();
                v1_2 = 0;
                while (true) {
                    label_16:
                    if (v1_2 >= v3) {
                        return ((b) v0_1);
                    }

                    if (!this.a(v1_2)) {
                        ((b) v0_1).a.add(this.a.get(v1_2));
                    }
                    ++v1_2;
                    continue;
                }
            } catch (CloneNotSupportedException v0) {
                CloneNotSupportedException v6 = v0;
                v1_1 = v6;
                v6.printStackTrace();
                return null;
            }
        }
    }

    private boolean a(int arg11) {
        long v8 = 1;
        long v6 = 0;
        boolean v0 = true;
        if (arg11 < 64) {
            if ((v8 << arg11 & this.b) == v6) {
                v0 = false;
            }
        } else if (this.c == null) {
            v0 = false;
        } else {
            int v2 = arg11 / 64 - 1;
            if (v2 >= this.c.length) {
                v0 = false;
            } else if ((this.c[v2] & v8 << arg11 % 64) == v6) {
                v0 = false;
            }
        }

        return v0;
    }

    private void a(int arg9, long arg10) {
        long v0 = -9223372036854775808L;
        int v2;
        for (v2 = arg9 + 63; v2 >= arg9; --v2) {
            if ((arg10 & v0) != 0) {
                this.a.remove(v2);
            }

            v0 >>>= 1;
        }
    }

    private void a(T arg8, int arg9, int arg10, int arg11, long arg12) {
        long v0 = 1;
        while (arg10 < arg11) {
            if ((arg12 & v0) == 0) {
                this.e.a(this.a.get(arg10), arg8, arg9);
            }

            v0 <<= 1;
            ++arg10;
        }
    }

    private void a(T arg9, int arg10, A arg11, int arg12) {
        if (arg12 < 0) {
            this.a(arg9, arg10, 0, Math.min(64, this.a.size()), this.b);
        } else {
            long v6 = this.c[arg12];
            int v4 = arg12 + 1 << 6;
            int v5 = Math.min(this.a.size(), v4 + 64);
            this.a(arg9, arg10, arg11, arg12 - 1);
            this.a(arg9, arg10, v4, v5, v6);
        }
    }

    public final void a(C arg2) {
        synchronized (this) {
            int v0_1 = this.a.lastIndexOf(arg2);
            if (v0_1 < 0 || (this.a(v0_1))) {
                this.a.add(arg2);
            }
        }
    }

    public void a(T arg11, int arg12, A arg13) {
        long v8 = 0;
        synchronized (this) {
            ++this.d;
            int v5 = this.a.size();
            int v0_1 = this.c == null ? -1 : this.c.length - 1;
            this.a(arg11, arg12, arg13, v0_1);
            this.a(arg11, arg12, v0_1 + 2 << 6, v5, 0);
            --this.d;
            if (this.d == 0) {
                if (this.c != null) {
                    for (v0_1 = this.c.length - 1; v0_1 >= 0; --v0_1) {
                        long v2 = this.c[v0_1];
                        if (v2 != v8) {
                            this.a(v0_1 + 1 << 6, v2);
                            this.c[v0_1] = 0;
                        }
                    }
                }

                if (this.b == v8) {
                    return;
                }

                this.a(0, this.b);
                this.b = 0;
            }
        }
    }

    public final void b(C arg11) {
        long v8 = 1;
        synchronized (this) {
            if (this.d == 0) {
                this.a.remove(arg11);
            } else {
                int v0_1 = this.a.lastIndexOf(arg11);
                if (v0_1 >= 0) {
                    if (v0_1 < 64) {
                        this.b |= v8 << v0_1;
                    } else {
                        int v1 = v0_1 / 64 - 1;
                        if (this.c == null) {
                            this.c = new long[this.a.size() / 64];
                        } else if (this.c.length < v1) {
                            long[] v2 = new long[this.a.size() / 64];
                            System.arraycopy(this.c, 0, v2, 0, this.c.length);
                            this.c = v2;
                        }

                        this.c[v1] |= v8 << v0_1 % 64;
                    }
                }
            }
        }
    }

    public Object clone() throws CloneNotSupportedException {
        return this.a();
    }
}

